<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1"/>
        <meta content="telephone=no,email=no" name="format-detection" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta content="yes" name="apple-touch-fullscreen">
		<title>老师-预约设置</title>
		<link rel="stylesheet" type="text/css" href="css/iosSelect.css"/>
		<link rel="stylesheet" type="text/css" href="css/basic.css"/>
		<link rel="stylesheet" type="text/css" href="css/layer.css"/>
		<link rel="stylesheet" type="text/css" href="css/student.css"/>
		<script src="js/jquery-3.1.1.min.js"></script>
		<script src="js/iosSelect.js"></script>
		<script src="js/layer.js"></script>
		<script src="js/common.js"></script>
		<script src="js/http.js"></script>
		<script>
			function tongyi(id){
				$.ajax({
					url:url+'tongyi',
					dataType:'json',
					type:'post',
					async:true,
					data:{
						'id':id
					},
					success:function(result){
						// console.log(result);
						var status = result.status;
						var code = result.code;
						if(status==1&&code=='1000'){
							alert('提交成功');
							centerinfo();
						}else if(status==1&&code=='1002') {
							alert('未登录');
							window.history.back();
						}else if(status==1&&code=='1008'){
							alert('已经关注过');
						}else{

							$('.order-list').html('没有预约信息');
						}
					},
					error:function(result){
						console.log(result);
					}
				})
			}
			function centerinfo(){
				$.ajax({
					url:url+'getteachinfo',
					dataType:'json',
					type:'post',
					async:true,
					data:{
					},
					success:function(result){
						// console.log(result);
						var status = result.status;
						var code = result.code;
						if(status==1&&code=='1000'){
							var data = result.data;
							var username = result.username;
							$('#username').html(username+'个人中心');
							if(data!=null&&data.length!=0){
								var html='';
								var techway ='';
								for(var i=0;i<data.length;i++){

									if(data[i]['techway']==1){
										techway ='学生上门';
									}else if(data[i]['techway']==2){
										techway ='老师上门';
									}

									html +='<li>'+
											'						<p><span>学员信息：</span>姓名:'+data[i]['xingming']+'<br/>'+'联系号码：<a href="'+data[i]['dianhua']+'"> '+data[i]['dianhua']+'</a></p>'+
											'						<p><span>地点：</span>'+data[i]['xingming']+'</p>'+
											'						<p><span>教学方式：</span>'+techway+'</p>';
									if(data[i]['astatus']==0){
										html += '<a href="javascript:void(0);" class="order-btns" onclick="tongyi('+data[i]['id']+')">同意</a></li>';
									}else if(data[i]['astatus']==1){
										html += '已经同意</li>';
									}
								}
								$('.order-list').html(html);
							}
							var teachyuyue =result.teachyuyue;
							$('#stdate').val(teachyuyue['stdate']);
							$('#sdate').html(teachyuyue['stdate']);
							$('#enddate').val(teachyuyue['enddate']);
							$('#edate').html(teachyuyue['enddate']);
							$('#week').val(teachyuyue['week']);
							$('.start-time').val(teachyuyue['sttime']);
							$('#stime').html(teachyuyue['sttime']);
							$('.end-time').val(teachyuyue['endtime']);
							$('#etime').html(teachyuyue['endtime']);
						}else if(status==1&&code=='1002') {
							alert('未登录');
							window.history.back();
						}else if(status==1&&code=='1008'){
							alert('已经关注过');
						}else{
                          $('.order-list').html('没有预约信息');
                          var teachyuyue =result.teachyuyue;
							if(teachyuyue!=''&&typeof(teachyuyue)!='undefined'){
								
								$('#stdate').val(teachyuyue['stdate']);
								$('#sdate').html(teachyuyue['stdate']);
								$('#enddate').val(teachyuyue['enddate']);
								$('#edate').html(teachyuyue['enddate']);
								$('#week').val(teachyuyue['week']);
								$('.start-time').val(teachyuyue['sttime']);
								$('#stime').html(teachyuyue['sttime']);
								$('.end-time').val(teachyuyue['endtime']);
								$('#etime').html(teachyuyue['endtime']);
							}

							
						}
					},
					error:function(result){
						console.log(result);
					}
				})

			}
			/**
			 * 设置老师的可预约的时间范围
			 */
			function shezhi(){
                var stdate = $('#stdate').val();
				var time1 = Date.parse(stdate);
				var enddate = $('#enddate').val();
				var time2 = Date.parse(enddate);
				if((stdate!=''&&enddate=='')||(stdate==''&&enddate!='')||(stdate==''&&enddate=='')){
					alert('请选择完整的日期');return;
				}
				if((time2 - time1)<0){
					alert('结束日期必须在开始日期之后');return;
				}
				if((Math.abs(time2 - time1))/1000/60/60/24>=14){
                    alert('最长时间间隔是14天');return;
				}
				var week = $('#week option:selected').val();
				var start_time = $('.start-time').val();
				var end_time = $('.end-time').val();
				if((start_time!=''&&end_time=='')||(start_time==''&&end_time!='')||(start_time==''&&end_time=='')){
					alert('请选择时间');return;
				}
				$.ajax({
					url:url+'teachyuyue',
					dataType:'json',
					type:'post',
					async:true,
					data:{
						'stdate':stdate,
						'enddate':enddate,
						'week':week,
						'sttime':start_time,
						'endtime':end_time
					},
					success:function(result){
						// console.log(result);
						var status = result.status;
						var code = result.code;
						if(status==1&&code=='1000'){
							alert('提交成功');
							centerinfo();
						}else if(status==1&&code=='1002') {
							alert('未登录');
							window.history.back();
						}else if(status==1&&code=='1008'){
							alert('已经关注过');
						}
					},
					error:function(result){
						console.log(result);
					}
				})

			}
			/**
			 *获取logo图片
			 */
			function getlogo(){
				$.ajax({
					url:url+'getlogo',
					type:'post',
					dataType:'json',
					success:function(result){
						var status = result.status;
						var code = result.code;
						if(status==1&&code=='1000'){
							var data = result.data;
                            $('#logo').attr('src',data['log']);
						}
					},
					error:function(result){
                       console.log(result);
					}
				})
			}

			$(function(){
				centerinfo();
				getlogo();
               $('.submit').click(function(){
				   shezhi();
			   })
			})
		</script>
	</head>
	<body>
		<header class="header" style="text-align: center;">
			<a href="javascript:window.history.back()" class="return-btn" ></a><div id="username" style="text-align: center;"></div>
		</header>
		<div id="set-order-wrapper">
			<!--学校logo-->
			<div class="item logo-item">
				<!--<div class="stu-title">
					<h1>学校logo</h1>
				</div>-->
				<div class="logo-box1">
					<img src="img/default.jpg" id="logo" style="height:3rem"/>
				</div>
			</div>
			<!--学校logo  end-->
			<!--已预约通知-->
			<div class="item order-item">
				<div class="stu-title">
					<h1>已预约通知</h1>
				</div>
				<ul class="order-list">
					<li>
						<p><span>学员信息：</span>某某<a href="tel: 15253565856"> 15253565856</a></p>
						<p><span>时间段：</span>周一 12:00-13:00，周一 12:00-13:00，周一 12:00-13:00，周一 12:00-13:00</p>
						<p><span>地点：</span>某某某</p>
						<p><span>教学方式：</span>老师上门</p>
					</li>
					<li>
						<p><span>学员信息：</span>某某<a href="tel: 15253565856"> 15253565856</a></p>
						<p><span>时间段：</span>周一 12:00-13:00，周一 12:00-13:00</p>
						<p><span>地点：</span>某某某</p>
						<p><span>教学方式：</span>老师上门</p>
					</li>
				</ul>
			</div>
			<!--已预约通知  end-->
			<!--预约时间设置-->
			<div class="item set-item">
				<div class="stu-title">
					<h1>我的预约时间设置</h1>
				</div>
				<div class="set-box">
					<form action="">
						<p><span class="name">开始日期：</span><input type="hidden" id="stdate"/><span class="choose dateChoose" id="sdate">选择开始时间</span></p>
						<p><span class="name">结束日期：</span><input type="hidden" id="enddate"/><span class="choose dateChoose" id="edate">选择结束时间</span></p>
						<div class="week-box">
							<span class="name">选择上课日：</span>
							<select id="week">
								<option value="1">星期一</option>
								<option value="2">星期二</option>
								<option value="3">星期三</option>
								<option value="4">星期四</option>
								<option value="5">星期五</option>
								<option value="6">星期六</option>
								<option value="7">星期日</option>
							</select>
							<!--<ul>
								<li data-index="1">
									星期一
								</li>
								<li data-index="2">
									星期二
								</li>
								<li data-index="3">
									星期三
								</li>
								<li data-index="4">
									星期四
								</li>
								<li data-index="5">
									星期五
								</li>
								<li data-index="6">
									星期六
								</li>
								<li data-index="7">
									星期日
								</li>
							</ul>-->
						</div>
						<!--<div class="week-select">
							
						</div>-->
						<div>
							<span class="name" >选择时间段：</span><dd><input type="hidden" class="start-time"/><span class="choose stimeChoose" id="stime">选择开始时间段</span>-<input type="hidden" class="end-time"/><span class="choose etimeChoose" id="etime">选择结束时间段</span></dd>
						</div>
						<input type="button" class="submit" value="设置"/>
					</form>
				</div>
			</div>
			<!--预约时间设置  end-->
		</div>
		<script type="text/javascript">
			/**
			 * 星期选择
			 *
			 */
			$(document).on("click",".week-box li",function(){
				if($(this).hasClass("active")){
					$(this).removeClass("active");
					$(".week-select dl[data-index='"+$(this).attr('data-index')+"']").remove()
				}else{
					$(this).addClass("active");
					//$(".week-select").append('<dl class="clearfix" data-index="'+$(this).attr("data-index")+'" style="float: left"><dt>'+$(this).html()+':<span class="fr add-btn"></span></dt></dl>')

					//$(".week-select").append('<dl class="clearfix" data-index="'+$(this).attr("data-index")+'"><dt>'+$(this).html()+':<span class="fr add-btn"></span></dt><dd><input type="hidden" class="start-time"/><span class="choose timeChoose">选择开始时间段</span>-<input type="hidden" class="end-time"/><span class="choose timeChoose">选择结束时间段</span></dd></dl>')
				}				
			});
//			添加时间段
			/*$(document).on("click",".week-select .add-btn",function(){
				$(this).closest("dl").append('<dd><input type="hidden" class="start-time"/><span class="choose timeChoose">选择开始时间段</span>-<input type="hidden" class="end-time"/><span class="choose timeChoose">选择结束时间段</span><span class="minus-btn fr"></span><dd>')			
			});*/
//			删除时间段
			/*$(document).on("click",".week-select .minus-btn",function(){
				$(this).closest("dd").remove()
			});*/
			/**
			 * 时间选择
			 */
			var hourData=[],minuteData=[]
			for(var i=1;i<25;i++){
				hourData.push({
					id:i,
					value:i
				});
			}
			for(var j=0;j<61;j++){
				if(j<10){
					minuteData.push({
						id:"0"+j,
						value:"0"+j
					});
				}else{
					minuteData.push({
						id:j,
						value:j
					});
				}				
			}
			$(document).on('click',".stimeChoose", function () {
		    	var selectDateDom = $(this);
		    	var showDateDom = $(this).siblings(".start-time");
		       	var oneLevelId = showDateDom.attr('data-year');
		        var twoLevelId = showDateDom.attr('data-month');
		        var threeLevelId = showDateDom.attr('data-date');
		        var iosSelect = new IosSelect(2, 
		            [hourData, minuteData],
		            {
		                title: '时间选择',
		                itemHeight: 35,
		                oneLevelId: oneLevelId,
		                twoLevelId: twoLevelId,
		                showLoading: true,
		                callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
		                    showDateDom.attr('data-hour', selectOneObj.value);
		                    showDateDom.attr('data-minute', selectTwoObj.value);
		                    selectDateDom.html(selectOneObj.value + ':' + selectTwoObj.value)
		                    showDateDom.val(selectOneObj.value + ':' + selectTwoObj.value);
		                }
		        });
		    });
			$(document).on('click',".etimeChoose", function () {
				var selectDateDom = $(this);
				var showDateDom = $(this).siblings(".end-time");
				var oneLevelId = showDateDom.attr('data-year');
				var twoLevelId = showDateDom.attr('data-month');
				var threeLevelId = showDateDom.attr('data-date');
				var iosSelect = new IosSelect(2,
						[hourData, minuteData],
						{
							title: '时间选择',
							itemHeight: 35,
							oneLevelId: oneLevelId,
							twoLevelId: twoLevelId,
							showLoading: true,
							callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
								showDateDom.attr('data-hour', selectOneObj.value);
								showDateDom.attr('data-minute', selectTwoObj.value);
								selectDateDom.html(selectOneObj.value + ':' + selectTwoObj.value)
								showDateDom.val(selectOneObj.value + ':' + selectTwoObj.value);
							}
						});
			});
			/**
			 * 日期选择
			 */
		    // 初始化时间
		    var now = new Date();
		    var nowYear = now.getFullYear();
		    var nowMonth = now.getMonth() + 1;
		    var nowDate = now.getDate();
		    // 数据初始化
		    function formatYear (nowYear) {
		        var arr = [];
		        for (var i = nowYear; i <= nowYear + 5; i++) {
		            arr.push({
		                id: i + '',
		                value: i 
		            });
		        }
		        return arr;
		    }
		    function formatMonth () {
		        var arr = [];
		        for (var i = 1; i <= 12; i++) {
		            arr.push({
		                id: i + '',
		                value: i 
		            });
		        }
		        return arr;
		    }
		    function formatDate (count) {
		        var arr = [];
		        for (var i = 1; i <= count; i++) {
		            arr.push({
		                id: i + '',
		                value: i 
		            });
		        }
		        return arr;
		    }
		    var yearData = function(callback) {
		            callback(formatYear(nowYear))
		    }
		    var monthData = function (year, callback) {
		            callback(formatMonth());
		    };
		    var dateData = function (year, month, callback) {
		            if (/^(1|3|5|7|8|10|12)$/.test(month)) {
		                callback(formatDate(31));
		            }
		            else if (/^(4|6|9|11)$/.test(month)) {
		                callback(formatDate(30));
		            }
		            else if (/^2$/.test(month)) {
		                if (year % 4 === 0 && year % 100 !==0 || year % 400 === 0) {
		                    callback(formatDate(29));
		                }
		                else {
		                    callback(formatDate(28));
		                }
		            }
		            else {
		                throw new Error('month is illegal');
		            }
		    };
		    $(".dateChoose").bind('click', function () {
		    	var selectDateDom = $(this);
		    	var showDateDom = $(this).siblings("input[type='hidden']");
		       	showDateDom.attr('data-year', nowYear);
			    showDateDom.attr('data-month', nowMonth);
			    showDateDom.attr('data-date', nowDate);
		       	var oneLevelId = showDateDom.attr('data-year');
		        var twoLevelId = showDateDom.attr('data-month');
		        var threeLevelId = showDateDom.attr('data-date');
		        var iosSelect = new IosSelect(3, 
		            [yearData, monthData, dateData],
		            {
		                title: '日期选择',
		                itemHeight: 35,
		                oneLevelId: oneLevelId,
		                twoLevelId: twoLevelId,
		                threeLevelId: threeLevelId,
		                showLoading: true,
		                callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
		                    showDateDom.attr('data-year', selectOneObj.id);
		                    showDateDom.attr('data-month', selectTwoObj.id);
		                    showDateDom.attr('data-date', selectThreeObj.id);
		                    selectDateDom.html(selectOneObj.value + '-' + selectTwoObj.value + '-' + selectThreeObj.value)
		                    showDateDom.val(selectOneObj.value + '-' + selectTwoObj.value + '-' + selectThreeObj.value);
		                }
		        });
		    });
		</script>
	</body>
</html>
